/*
 * exame_2009_10_julho_Q1.c
 *
 *  Created on: Jun 19, 2012
 *      Author: ubuntu
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int somadivit(int a) {
	int aAux = 0;
	int somatorio = 0;
	for (aAux = a; aAux > 0; aAux--) {
		if (a % aAux == 0) {
			somatorio += aAux;
		}
	}
	return somatorio;
}

int somadivrec(int a, int aAux) {

	if (aAux > 0) {
		int somatorio = 0;
		if (a % aAux == 0) {
			somatorio = aAux;
		}
		return somatorio + somadivrec(a, --aAux);
	}

	return 0;
}

int main(int argc, char **argv) {
	if (argc < 2) {
		fprintf(stderr, "Usage %s <a>\n", argv[0]);
		exit(EXIT_FAILURE);
	}

	printf("It: %d\n", somadivit(atoi(argv[1])));
	printf("Rec: %d\n", somadivrec(atoi(argv[1]), atoi(argv[1])));

	return 0;
}

